//
//  SDebugWindow.m
//  EasyRetail
//
//  Created by Samuel on 11/30/15.
//
//

#import "SDebugWindow.h"
#import "SHTTPClient.h"
#import <CoreData/CoreData.h>
#import "SCoreData.h"
#import <objc/runtime.h>

@interface SDebugWindow ()


@end
@implementation SDebugWindow
{
    NSMutableArray *allDataArray;
    
    NSMutableArray *requestArray;
    NSMutableArray <NSString*>* rHeightArray;
    
    NSMutableArray *coreDataArray;
    NSMutableArray <NSString*>* cHeightArray;
    
    UITableView *tableViews;
    
    UIView *bgView;
    UIButton *cleanData;
    UIButton *closeWindow ;
    UISegmentedControl *segmenteds;
    UIButton *editWindowFrame;
    UIButton *toBottom;
    
    BOOL isOpenEdit;
    NSInteger segmentedInteger;
    
    NSInteger sectionNumber;
    NSString *saveDbName;
}

+ (SDebugWindow*)shareSDebugWindowInitialization;
{
    SDebugWindow *sDebugWindow = [[SDebugWindow alloc]initWithFrame:CGRectMake(0, 0, 200, 240)];
    sDebugWindow.layer.masksToBounds = YES;
    sDebugWindow.layer.cornerRadius = 1.5;
    sDebugWindow.layer.borderColor = [UIColor colorWithRed:139.0/255 green:178.0/255 blue:38.0/255 alpha:1].CGColor;
    [sDebugWindow setBackgroundColor:[UIColor blackColor]];
    
    NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator];
    for (UIWindow *window in frontToBackWindows)
    {
        if (window.windowLevel == UIWindowLevelNormal) {
            [sDebugWindow setCenter:window.center];
            sDebugWindow.alpha = 0;
            [window addSubview:sDebugWindow];
            [UIView animateWithDuration:.2 animations:^{
                sDebugWindow.alpha = 1;
            }];
            break;
        }
    }
    UIPanGestureRecognizer *pans = [[UIPanGestureRecognizer alloc]initWithTarget:sDebugWindow action:@selector(handlePan:)];
    [sDebugWindow addGestureRecognizer:pans];
    [sDebugWindow setBackgroundColor:[UIColor colorWithRed:139.0/255 green:178.0/255 blue:38.0/255 alpha:1]];
    
    
    return sDebugWindow;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        requestArray = [[NSMutableArray alloc]init];
        HttpModels *htm = [[HttpModels alloc]init];
        htm.urlString = @"*debug window";
        htm.requestString = @"*";
        [requestArray addObject:htm];
        
        rHeightArray = [[NSMutableArray alloc]init];
        coreDataArray = [[NSMutableArray alloc]init];
        cHeightArray = [[NSMutableArray alloc]init];
        allDataArray = requestArray;
        
        [self setUpDbDatas:@"EasyRetail"];
        [self setUpDbDatas:@"MemberTag"];
        [self setUpDbDatas:@"TestDB"];
        [self setUpDbDatas:@"Statistics"];
        [self setUpDbDatas:@"PushInfo"];
        
        sectionNumber = 0;
        
        bgView = [[UIView alloc]initWithFrame:frame];
        [bgView setCenter:self.center];
        [bgView setBackgroundColor:[UIColor darkGrayColor]];
        [self addSubview:bgView];
        
        [self setTableView];
        
        cleanData = [UIButton buttonWithType:UIButtonTypeCustom];
        [cleanData setFrame:CGRectMake(CGRectGetWidth(self.frame)-2.5-30, 2.5, 30, 20)];
        [cleanData setBackgroundColor:[UIColor clearColor]];
        [cleanData setTitle:@"Empty" forState:UIControlStateNormal];
        [cleanData.titleLabel setFont:[UIFont systemFontOfSize:9]];
        [cleanData setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        cleanData.layer.borderWidth = 1;
        cleanData.layer.borderColor = [UIColor whiteColor].CGColor;
        cleanData.layer.cornerRadius = 3;
        cleanData.layer.masksToBounds = YES;
        [cleanData addTarget:self action:@selector(cleanOrRefreshDatas:) forControlEvents:UIControlEventTouchDown];
        [bgView addSubview:cleanData];
        
        closeWindow = [UIButton buttonWithType:UIButtonTypeCustom];
        [closeWindow setFrame:CGRectMake(2.5, 2.5, 20, 20)];
        [closeWindow setBackgroundColor:[UIColor redColor]];
        [closeWindow setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        closeWindow.layer.borderWidth = 1;
        closeWindow.layer.borderColor = [UIColor whiteColor].CGColor;
        closeWindow.layer.cornerRadius = 3;
        closeWindow.layer.masksToBounds = YES;
        [closeWindow setTitle:@"X" forState:UIControlStateNormal];
        [closeWindow.titleLabel setFont:[UIFont systemFontOfSize:9]];
        closeWindow.titleLabel.textAlignment = NSTextAlignmentCenter;
        [closeWindow addTarget:self action:@selector(closeWindows:) forControlEvents:UIControlEventTouchDown];
        [bgView addSubview:closeWindow];
        
        segmenteds = [[UISegmentedControl alloc]initWithItems:@[@"https",@"codat"]];
        segmenteds.selectedSegmentIndex = 0;
        [segmenteds addTarget:self action:@selector(segmentedsAction:) forControlEvents:UIControlEventValueChanged];
        [segmenteds setFrame:CGRectMake(CGRectGetWidth(self.frame)-5-90, 2.5, 60, 20)];
        [segmenteds setTintColor:[UIColor whiteColor]];
        UIFont *font = [UIFont boldSystemFontOfSize:9.0f];
        NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
        [segmenteds setTitleTextAttributes:attributes forState:UIControlStateNormal];
        [bgView addSubview:segmenteds];
        
        editWindowFrame = [UIButton buttonWithType:UIButtonTypeCustom];
        [editWindowFrame setFrame:CGRectMake(2.5, CGRectGetHeight(self.frame)-22.5, 20, 20)];
        [editWindowFrame setBackgroundColor:[UIColor colorWithRed:139.0/255 green:178.0/255 blue:38.0/255 alpha:1]];
        [editWindowFrame setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        editWindowFrame.layer.borderWidth = 1;
        editWindowFrame.layer.borderColor = [UIColor whiteColor].CGColor;
        editWindowFrame.layer.cornerRadius = 3;
        editWindowFrame.layer.masksToBounds = YES;
        [editWindowFrame setTitle:@"+" forState:UIControlStateNormal];
        [editWindowFrame setTitle:@"o" forState:UIControlStateSelected];
        [editWindowFrame.titleLabel setFont:[UIFont systemFontOfSize:9]];
        editWindowFrame.titleLabel.textAlignment = NSTextAlignmentCenter;
        [editWindowFrame addTarget:self action:@selector(editWindowFrame:) forControlEvents:UIControlEventTouchDown];
        [bgView addSubview:editWindowFrame];
        
        
        
        toBottom = [UIButton buttonWithType:UIButtonTypeCustom];
        [toBottom setFrame:CGRectMake(CGRectGetWidth(self.frame)-2.5-20, CGRectGetHeight(self.frame)-22.5, 20, 20)];
        [toBottom setBackgroundColor:[UIColor colorWithRed:139.0/255 green:178.0/255 blue:38.0/255 alpha:1]];
        [toBottom setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        toBottom.layer.borderWidth = 1;
        toBottom.layer.borderColor = [UIColor whiteColor].CGColor;
        toBottom.layer.cornerRadius = 3;
        toBottom.layer.masksToBounds = YES;
        [toBottom setTitle:@"!" forState:UIControlStateNormal];
        [toBottom.titleLabel setFont:[UIFont systemFontOfSize:9]];
        toBottom.titleLabel.textAlignment = NSTextAlignmentCenter;
        [toBottom addTarget:self action:@selector(toBottomAction:) forControlEvents:UIControlEventTouchDown];
        [bgView addSubview:toBottom];
        
        isOpenEdit = NO;
    }
    return self;
}
- (void)setUpDbDatas:(NSString*)dbName
{
    DbModels *dbModels = [[DbModels alloc]init];
    dbModels.dbName = dbName;
    dbModels.cdModelArray = [[NSMutableArray alloc]init];
    NSString *firstStringDb = [NSString stringWithFormat:@"(Tap here for back) Db_Name: %@ ",dbName];
    [dbModels.cdModelArray addObject:firstStringDb];
    [coreDataArray addObject:dbModels];
    
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:dbName withExtension:@"momd"];
    NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    NSDictionary *myEntities = [managedObjectModel entitiesByName];
    NSArray *keys = [myEntities allKeys];
    
    for (int i = 0;i<keys.count ;i++) {
        NSString *key = [keys objectAtIndex:i];
        CoreDataModels *cdm = [[CoreDataModels alloc]init];
        cdm.tableName = key;
        cdm.dbDataArray = [[NSMutableArray alloc]init];
        cdm.dbName = dbName;
        [dbModels.cdModelArray addObject:cdm];
        
        NSArray *objs = [myEntities allValues];
        NSEntityDescription *one = [objs objectAtIndex:i];
        NSArray *proArr = one.properties;
        NSString *titleName = @"(Tap here for back) Entity_Name: ";
        for (NSAttributeDescription *gets in proArr) {
            if (gets.name) {
                titleName = [titleName stringByAppendingString:[NSString stringWithFormat:@"\n'%@'",gets.name]];
            }
        }
        [cdm.dbDataArray addObject:titleName];
    }
}
#pragma mark - Button Action
- (void)closeWindows:(UIButton*)sender
{
    [self removeFromSuperview];
}
- (void)cleanOrRefreshDatas:(UIButton*)sender
{
    if ([sender.titleLabel.text isEqualToString:@"Refsh"]) {
        //        allDataArray = coreDataArray;
        //        [tableViews reloadData];
        //        [tableViews selectRowAtIndexPath:[NSIndexPath indexPathForRow:(allDataArray.count -1) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
        return;
    }
    [requestArray removeAllObjects];
    HttpModels *htm = [[HttpModels alloc]init];
    htm.urlString = @"*debug window";
    htm.requestString = @"*";
    htm.finishDate = @"";
    [requestArray addObject:htm];
    [rHeightArray removeAllObjects];
    [tableViews reloadData];
}
- (void)editWindowFrame:(UIButton*)sender
{
    if (sender.selected == NO) {
        sender.selected = YES;
        [UIView animateWithDuration:.2 animations:^{
            self.layer.borderWidth = 2;
        }];
        isOpenEdit = YES;
    }
    else
    {
        sender.selected = NO;
        [UIView animateWithDuration:.2 animations:^{
            self.layer.borderWidth = 0;
        }];
        [self getRequestHeightData];
        if (allDataArray.count>0) {
            [tableViews selectRowAtIndexPath:[NSIndexPath indexPathForRow:(allDataArray.count -1) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
        }
        
        isOpenEdit = NO;
    }
}
- (void)toBottomAction:(UIButton*)sender
{
    [tableViews scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:allDataArray.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
#pragma mark - Segmented control Action
- (void)segmentedsAction:(UISegmentedControl*)sender
{
    segmentedInteger = sender.selectedSegmentIndex;
    if (sender.selectedSegmentIndex == 0) {
        [cleanData setTitle:@"Empty" forState:UIControlStateNormal];
        sectionNumber = 0;
        allDataArray = requestArray;
        if (allDataArray.count<1) {
            return;
        }
    }
    else
    {
        [cleanData setTitle:@"Refsh" forState:UIControlStateNormal];
        allDataArray = coreDataArray;
    }
    [tableViews reloadData];
    [tableViews selectRowAtIndexPath:[NSIndexPath indexPathForRow:(allDataArray.count -1) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
#pragma mark - Set Request Data
- (void)showDatasWithObject:(id)object andUrl:(NSString*)url;
{
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:nil];
    NSString *gString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    HttpModels *htm = [[HttpModels alloc]init];
    htm.urlString = [NSString stringWithFormat:@"Url:%@",url];
    htm.requestString = gString;
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"hh:mm:ss"];
    htm.finishDate = [formatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:0]];
    [requestArray insertObject:htm atIndex:0];
    [self getRequestHeightData];
    //    if (segmentedInteger == 0 ) {
    //        [tableViews selectRowAtIndexPath:[NSIndexPath indexPathForRow:(requestArray.count -1) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    //    }
}
#pragma mark - commit Hight
- (void)getRequestHeightData
{
    [rHeightArray removeAllObjects];
    for (int i = 0 ; i<requestArray.count; i++) {
        HttpModels *htm = [requestArray objectAtIndex:i];
        NSString *k = htm.urlString;
        NSString *o = htm.requestString;
        NSString *n = [NSString stringWithFormat:@"%@ -> %@",k,o];
        CGSize size = [n boundingRectWithSize:CGSizeMake(CGRectGetWidth(tableViews.frame)-20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11.]} context:nil].size;
        NSString *ss = NSStringFromCGSize(size);
        [rHeightArray addObject:ss];
    }
    [tableViews reloadData];
}
- (void)getCoreDataHeightData:(NSMutableArray*)array
{
    [cHeightArray removeAllObjects];
    if (sectionNumber == 1) {
        CGSize size = [[array objectAtIndex:0] boundingRectWithSize:CGSizeMake(CGRectGetWidth(tableViews.frame)-20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11.]} context:nil].size;
        NSString *ss = NSStringFromCGSize(size);
        [cHeightArray addObject:ss];
        for (int i = 0;i<array.count;i++) {
            CGSize size2 = CGSizeMake(0, 20);
            NSString *ss = NSStringFromCGSize(size2);
            [cHeightArray addObject:ss];
        }
    }
    else if (sectionNumber == 2)
    {
        for (NSString *gets in array) {
            CGSize size = [gets boundingRectWithSize:CGSizeMake(CGRectGetWidth(tableViews.frame)-20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11.]} context:nil].size;
            NSString *ss = NSStringFromCGSize(size);
            [cHeightArray addObject:ss];
        }
    }
}
#pragma mark - show self
- (void)showDebugWindow
{
    NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator];
    for (UIWindow *window in frontToBackWindows)
    {
        if (window.windowLevel == UIWindowLevelNormal) {
            [self setCenter:self.center];
            self.alpha = 0;
            [window addSubview:self];
            [UIView animateWithDuration:.2 animations:^{
                self.alpha = 1;
            }];
            break;
        }
    }
}
#pragma mark - Pan action
- (void)handlePan:(UIPanGestureRecognizer*)sender
{
    CGPoint point = [sender translationInView:self];
    if (isOpenEdit==YES) {
        switch ([sender state]) {
            case UIGestureRecognizerStateBegan:
                break;
            case UIGestureRecognizerStateChanged:
            {
                float newWidth = ((CGRectGetWidth(sender.view.frame)+point.x)<=120)?120:CGRectGetWidth(sender.view.frame)+point.x;
                float newHeight = ((CGRectGetHeight(sender.view.frame)+point.y)<=100)?100:CGRectGetHeight(sender.view.frame)+point.y;
                [sender.view setFrame:CGRectMake(sender.view.frame.origin.x, sender.view.frame.origin.y,newWidth ,newHeight )];
                [bgView setFrame:CGRectMake(bgView.frame.origin.x, bgView.frame.origin.y, newWidth, newHeight)];
                [tableViews setFrame:CGRectMake(0, 25, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)-50)];
                [cleanData setFrame:CGRectMake(CGRectGetWidth(self.frame)-2.5-30, 2.5, 30, 20)];
                [editWindowFrame setFrame:CGRectMake(2.5, CGRectGetHeight(self.frame)-22.5, 20, 20)];
                [segmenteds setFrame:CGRectMake(CGRectGetWidth(self.frame)-5-90, 2.5, 60, 20)];
                [sender setTranslation:CGPointMake(0, 0) inView:self];
                
                break;
            }
            case UIGestureRecognizerStateEnded:
            {
                break;
            }
            default:
                break;
        }
        return;
    }
    switch ([sender state]) {
        case UIGestureRecognizerStateBegan:
            break;
        case UIGestureRecognizerStateChanged:
        {
            sender.view.center = CGPointMake(sender.view.center.x + point.x, sender.view.center.y + point.y);
            [sender setTranslation:CGPointMake(0, 0) inView:self];
            break;
        }
        case UIGestureRecognizerStateEnded:
        {
            break;
        }
        default:
            break;
    }
}

#pragma mark - tableView Set
- (void)setTableView
{
    tableViews = [[UITableView alloc]initWithFrame:CGRectMake(0, 25, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)-50) style:UITableViewStylePlain];
    [tableViews setBackgroundColor:[UIColor blackColor]];
    tableViews.delegate = self;
    tableViews.dataSource = self;
    [bgView addSubview:tableViews];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return allDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cells"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cells"];
        cell.textLabel.font = [UIFont systemFontOfSize:10];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.textColor = [UIColor greenColor];
        [cell setBackgroundColor:[UIColor blackColor]];
    }
    if (segmentedInteger==0) {
        HttpModels *htm = [allDataArray objectAtIndex:indexPath.row];
        cell.textLabel.text = [NSString stringWithFormat:@"时间:%@\n%@\n%@\n",htm.finishDate,htm.urlString,htm.requestString];
        return cell;
    }
    else
    {
        if (sectionNumber == 0) {
            DbModels *getDbs = [allDataArray objectAtIndex:indexPath.row];
            cell.textLabel.text = [NSString stringWithFormat:@".:%@",getDbs.dbName];
        }
        if (sectionNumber == 1) {
            if (indexPath.row == 0) {
                cell.textLabel.text = [NSString stringWithFormat:@"~ %@",[allDataArray objectAtIndex:0]];
            }
            else{
                CoreDataModels *gets = [allDataArray objectAtIndex:indexPath.row];
                cell.textLabel.text = [NSString stringWithFormat:@".:%@",gets.tableName];
            }
        }
        if (sectionNumber == 2) {
            if (indexPath.row == 0) {
                cell.textLabel.text = [NSString stringWithFormat:@"~ %@",[allDataArray objectAtIndex:0]];
            }
            else{
                cell.textLabel.text = [NSString stringWithFormat:@".:%@",[allDataArray objectAtIndex:indexPath.row]];
            }
        }
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (segmentedInteger == 1) {
        if ((indexPath.row ==0 && sectionNumber==0)||(indexPath.row >0 )) {
            if ([[[allDataArray objectAtIndex:indexPath.row]class]isSubclassOfClass:[CoreDataModels class]]) {
                CoreDataModels *cdm = [allDataArray objectAtIndex:indexPath.row];
                NSString *firstString = [[NSString alloc]initWithString:[cdm.dbDataArray objectAtIndex:0]];
                [cdm.dbDataArray removeAllObjects];
                [cdm.dbDataArray addObject:firstString];
                [cdm.dbDataArray addObjectsFromArray:[self getCoredata:cdm.tableName andDbName:cdm.dbName]];
                allDataArray = cdm.dbDataArray;
                sectionNumber = 2;
                [self getCoreDataHeightData:allDataArray];
                
            }
            else if ([[[allDataArray objectAtIndex:indexPath.row]class]isSubclassOfClass:[DbModels class]])
            {
                DbModels *cdm = [allDataArray objectAtIndex:indexPath.row];
                allDataArray = cdm.cdModelArray;
                sectionNumber = 1;
                saveDbName = cdm.dbName;
                [self getCoreDataHeightData:allDataArray];
            }
            [tableView reloadData];
            return;
        }
        if (indexPath.row == 0 && sectionNumber>0)
        {
            sectionNumber--;
            if (sectionNumber == 0) {
                allDataArray = coreDataArray;//dbModel
            }
            else if (sectionNumber == 1)
            {
                //table-CoreDataModel
                for (DbModels *gets in coreDataArray) {
                    if ([gets.dbName isEqualToString:saveDbName]) {
                        allDataArray = gets.cdModelArray;
                    }
                }
                //                CoreDataModels *cdm = [allDataArray objectAtIndex:indexPath.row];
                //                DbModels *gets ;
                //                for (DbModels *gDbM in coreDataArray) {
                //                    if ([gDbM.dbName isEqualToString:cdm.dbName]) {
                //                        gets = gDbM;
                //                    }
                //                }
                //                allDataArray = gets.cdModelArray;
            }
            [tableView reloadData];
            
        }
        
    }
    
}

- (NSMutableArray<NSString*>*)getCoredata:(NSString *)tableName andDbName:(NSString*)dbName
{
    SCoreData *manage = [[SCoreData sharedInstance]setTableName:tableName andDatabaseName:dbName];
    NSMutableArray *getArray = [manage selectData:200000 andOffset:0 andCompositorKey:nil];
    if (getArray.count>0) {
        NSMutableArray <NSString*>*arras = [NSMutableArray array];
        for (id objects in getArray) {
            [arras addObject:[self getDictionaryBasicModel:objects]];
        }
        return arras;
    }
    return nil;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (segmentedInteger == 0) {
        if(rHeightArray.count <1)
        {
            return 10;
        }
        float x = CGSizeFromString(rHeightArray[indexPath.row]).height;
        return x;
    }
    else
    {
        if (sectionNumber == 2) {
            float y = CGSizeFromString(cHeightArray[indexPath.row]).height;
            return y;
        }
        return 20;
    }
}
- (NSString *)getDictionaryBasicModel:(NSObject *)baseModel
{
    NSString *modelString = @"~";
    unsigned int outCount, i;
    objc_property_t *properties =class_copyPropertyList([baseModel class], &outCount);
    for (i = 0; i<outCount; i++)
    {
        objc_property_t property = properties[i];
        const char* char_f =property_getName(property);
        NSString *propertyName = [NSString stringWithUTF8String:char_f];
        id value = [baseModel valueForKey:propertyName];
        modelString = [modelString stringByAppendingPathComponent:[NSString stringWithFormat:@"\n%@:::%@",propertyName,((value)?value:@"null")]];
    }
    return modelString;
}
@end


@implementation HttpModels
@end
@implementation CoreDataModels
@end
@implementation DbModels
@end
